package cn.promonkey.blog.common.sms;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 短信验证码服务自动配置，默认阿里云短信服务
 * @author: guoxy 增加log验证码输出，不走短信平台
 * @create: 2020-12-03
 **/
@Log4j2
@Configuration
@EnableConfigurationProperties({SmsServiceProperties.class})
public class SmsAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public SmsCodeService smsService(SmsServiceProperties properties) {
        int type = properties.getType();
        SmsCodeService smsCodeService = null;
        switch(type) {
        case 1:smsCodeService=new AliSmsCodeService(properties); break;
        case 2:smsCodeService=new TencentSmsCodeService(properties); break;
        default:smsCodeService=new LogSmsCodeService(properties); break;
        }
        return smsCodeService;
        
		/*
		 * if (type == 1) { return new AliSmsCodeService(properties); } return new
		 * TencentSmsCodeService(properties);
		 */
    }
}
